<?php

/*
 * 比赛情况表
 * @author yangchao
 * @package qqjiazu
 * @copyright yangchao
 * @version 1.2
 * @code-encode utf-8
 * @data-encode utf-8
*/

class db_mod_game_info extends db_base
{
	var $tbl_name = "game_info";

	function db_mod_game_info()
	{
		parent::db_base();
	}


	/**
	 * 根据 qid取总数
	 * @param $current_site_id
	 * @param $product_id
	 */
	function get_game_info_count_by_qid($qid)
	{
		$where_arr = array();
		$where_arr[] =" qid = {$qid} ";
		$where_arr[] =" status = 1 ";
		$where = implode(' AND ', $where_arr);
		 
		$mc = mem_cache::get_instance();
		$key = CACHE_USER_ACHIEVEMENT_LIST . "-get_game_info_count_by_qid-{$qid}";
		$cache = $mc->get($key);
		if ($cache === false)
		{
			$content = $this->get_listcount($this->tbl_name,$where);
			// 保存MC
			$mc->set($key, serialize($content), 0, CACHE_TIME_USER_ACHIEVEMENT_LIST);
		}
		else
		{
			$content = unserialize($cache);
		}

		return $content;
	}



	/**
	 * 前台显示成就列表
	 * @param $p
	 * @param $pcount
	 * @param $current_site_id
	 * @param $product_id
	 */
	function get_game_info_list_by_qid( $qid,$p=1, $pcount=10)
	{       
	
		$where_arr = array();
		$where_arr[] =" qid = {$qid} ";
		$where_arr[] =" status = 1 ";
		$where = implode(' AND ', $where_arr);
		 
		$data = false;
		$key = CACHE_USER_ACHIEVEMENT_LIST . "-get_game_info_list_by_qid-{$qid}-{$p}-{$pcount}";
		$mc = mem_cache::get_instance();
		$cache = $mc->get($key);
		if ($cache === false)
		{
			$data = $this->get_alllist($this->tbl_name, $p, $pcount, " create_time desc ",$where);
			$mc->set($key, serialize($data), 0, CACHE_TIME_USER_ACHIEVEMENT_LIST);
		}
		else
		{
			$data = unserialize($cache);
		}

		return $data;
	}
	

	/**
	 * 前台显示单条数据
	 * @param $achievement_id
	 */
	function get_item($game_info_id)
	{       
		$game_info_id = intval($game_info_id);
		$where_arr = array();
		
		$where = " game_info_id = {$game_info_id}  and status = 1 " ;
		 
		$data = false;
		$key = CACHE_USER_ACHIEVEMENT_LIST . "-get_item-{$game_info_id}";
		$mc = mem_cache::get_instance();
		$cache = $mc->get($key);
		if ($cache === false)
		{
			$data = $this->get_alllist($this->tbl_name, 1, 1, "",$where);
			$mc->set($key, serialize($data), 0, CACHE_TIME_USER_ACHIEVEMENT_LIST);
		}
		else
		{
			$data = unserialize($cache);
		}

		return $data;
	}	
	
	



	/**
	 * 管理员删除 信息
	 * @param unknown_type $current_uid
	 * @param unknown_type $achievement_id
	 */
	function admin_del_game_info($admin_uid, $game_info_id)
	{
	
		$achievement_id = intval($achievement_id);
		// 删除数据库
		$ary = array();
		
		$ary["update_time"] = Date::get_date_time();
		$ary["update_ip"] = IP::get_client_ip_long();
		$ary["update_uid"] = $admin_uid;
		$ary["status"] = 0;
		
		$ret=$this->update($this->tbl_name, $ary, " game_info_id='{$game_info_id}'");
		if ($ret)
		{
			$info = $this->admin_get_item($game_info_id);
			
			$test  = $info[0]["test"];
			
			global $config;
			$curl = new Curl_Class();
			$url = $config["delete_mc_url"][$config["current_site_id"]];
			$key[] = CACHE_USER_ACHIEVEMENT_LIST . "-get_achievement_by_user_action_id-{$test}";
			$key[] = CACHE_USER_ACHIEVEMENT_LIST . "-get_achievement_is_show_by_user_action_id-{$test}";
			$keys = implode(",",$key);
			$curl->post($url,"keys=".$keys);
		
		}
		else
		{
			return false;
		}



		return true;
	}


	/**
	 * 后台取单条数据
	 */
	function admin_get_item($game_info_id)
	{       
		$achievement_id = intval($game_info_id);
		$where_arr = array();
		$where = " game_info_id = {$game_info_id} " ;
		$data = $this->get_alllist($this->tbl_name, 1, 1, "",$where);
		return $data;
	}	
	


}
?>
